package fr.cephb.operonj.core.bio;

import java.io.Serializable;
import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;



@XmlRootElement(name="build")
public class Build
implements Serializable
{
private static final long serialVersionUID = 1L;
@XmlAttribute(required=true)
private int id;
@XmlElement(required=true,nillable=false)
private String label;
@XmlElement(required=true,nillable=false)
private String description;
@XmlElement(required=true,nillable=false)
private String taxName;
@XmlElement(required=true,nillable=false)
private int taxId;

@SuppressWarnings("unused")
private Build()
	{
	
	}
public Build(int id,String label,String description,int taxId, String taxName)
	{
	this.id=id;
	this.label=label;
	this.description=description;
	this.taxId=taxId;
	this.taxName=taxName;
	assert(this.id>0);
	assert(this.taxId>0);
	assert(this.label!=null);
	assert(this.taxName!=null);
	}

/** unique ID for this assembly */
public int getId() {
	return id;
}



/** name/description for this assembly */
public String getLabel() {
	return label;
}

public String getDescription()
	{
	return description;
	}

/** ncbi taxon id */
public int getTaxId() {
	return taxId;
}

/** ncbi taxon name */
public String getTaxName() {
	return taxName;
}

@Override
public int hashCode()
	{
	final int prime = 31;
	int result = 1;
	result = prime * result + id;
	return result;
	}

@Override
public boolean equals(Object obj)
	{
	if (this == obj) return true;
	if (obj == null) return false;
	if (!(obj instanceof Build)) return false;
	Build other = (Build) obj;
	if (id != other.id) return false;
	return true;
	}

@Override
public String toString()
	{
	return "{id:"+getId()+",name:"+getLabel()+",taxid:"+getTaxId()+"}";
	}
public static void main(String[] args)
	{
	try{
	JAXBContext context = JAXBContext.newInstance(Build.class);
	
    
	Marshaller marshaller = context.createMarshaller();
    Unmarshaller unmarshaller=context.createUnmarshaller();
    for(int i=0;i< 100;++i)
    	{
	    Build o=new Build(0,"name","",i,"Homo");
	    StringWriter out= new StringWriter();
	    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
	    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
	    marshaller.marshal(o,out);
	    System.err.println(out.toString());
	    Object p=unmarshaller.unmarshal(new StringReader(out.toString()));
	    System.err.println(p);
		} 
	}
catch (Exception e)
	{
    e.printStackTrace();
    }

}
}
